package com.lihui;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.text.MessageFormat;

/**
 * 功能描述
 *
 * @author wileda
 * @date 2023/04/02  17:18
 */
@WebServlet("/Parameter")
public class ParameterServlet extends HttpServlet {

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("utf-8");
        String studentId = req.getParameter("studentId");
        String studentName = req.getParameter("studentName");

        String str = MessageFormat.format(" POST :studentId = {0},studentName = {1}", studentId,studentName);
        System.out.println(str );
        resp.setContentType("text/html; charset =  UTF-8");

        resp.getWriter().write(str);
    }

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("utf-8");
        String studentId = req.getParameter("studentId");
        String studentName = req.getParameter("studentName");

        String str = MessageFormat.format("GET: studentId = {0},studentName = {1}", studentId,studentName);
        System.out.println(str );
        resp.setContentType("text/html; charset =  UTF-8");

        resp.getWriter().write(str);
    }
}
